<template>
  <div class="note-detail-mask" @click="closeModal">
    <!-- 关闭按钮 -->
    <div class="close-cricle" @click.stop="$emit('close')">
      <div class="close close-mask-white">
        <el-icon><Close /></el-icon>
      </div>
    </div>

    <div class="note-container" v-if="!loading" @click.stop>
      <!-- 媒体轮播 -->
      <div class="media-container">
        <el-carousel height="90vh" v-if="article.media && article.media.length > 0">
          <el-carousel-item v-for="(item, index) in article.media" :key="index">
            <el-image
                style="width: 100%; height: 100%"
                :src="item"
                fit="cover"
            />
          </el-carousel-item>
        </el-carousel>
        <div v-else class="no-media">
          <el-empty description="暂无图片" />
        </div>
      </div>

      <!-- 互动区域 -->
      <div class="interaction-container">
        <div class="author-container">
          <div class="author-me">
            <div class="info">
              <img
                  class="avatar-item"
                  style="width: 40px; height: 40px; object-fit: cover;"
                  :src="article.author.avatar || getDefaultAvatarUrl()"
                  @click="goToUserProfile(article.author.id)"
              />
              <span class="name">{{ article.author.name }}</span>
            </div>
            <div class="follow-btn" v-if="!isSelf">
              <el-button
                  :type="isFollowed ? 'default' : 'danger'"
                  size="large"
                  round
                  @click="toggleFollow"
              >
                {{ isFollowed ? '已关注' : '关注' }}
              </el-button>
            </div>
          </div>

          <div class="note-scroller">
            <div class="note-content">
              <div class="title">{{ article.title }}</div>
              <div class="desc">
                <span>{{ article.content }} <br /></span>
                <a
                    v-for="(tag, index) in article.tags"
                    :key="index"
                    class="tag tag-search"
                >
                  {{ tag }}
                </a>
              </div>
              <div class="bottom-container">
                <span class="date">{{ formatDate(article.creationTime) }}</span>
              </div>
            </div>
            <div class="divider interaction-divider"></div>

            <!-- 评论 -->
            <div class="comments-el">
              <div class="comments-container">
                <!-- 总评论数 -->
                <div class="total">共 {{ totalComments }} 条评论</div>

                <!-- 父评论列表 -->
                <div class="list-container">
                  <div v-for="comment in topLevelComments" :key="comment.commentID" class="parent-comment">
                    <!-- 父评论 -->
                    <div class="comment-item">
                      <div class="comment-inner-container">
                        <div class="avatar">
                          <img class="avatar-item" :src="comment.userInfo.headshot || getDefaultAvatarUrl()" @click="goToUserProfile(comment.userInfo.userID)" alt="User Avatar" />
                        </div>
                        <div class="right">
                          <div class="author-wrapper">
                            <div class="author"><a class="name">{{ comment.userInfo.username }}</a></div>
                          </div>
                          <div class="content">{{ comment.content }}</div>
                          <div class="info">
                            <div class="time">{{ formatDate(comment.creationTime) }}</div>
                            <div class="interactions">
                              <div class="reply" @click="replyToComment(comment)">
                                <el-icon><ChatDotRound /></el-icon>
                                回复
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <!-- 子评论列表 -->
                    <div v-if="comment.replies && comment.replies.length > 0" class="replies-container">
                      <div class="replies-wrapper" :class="{ expanded: expandedComments[comment.commentID] }">
                        <div v-for="reply in comment.replies" :key="reply.commentID" class="reply-item">
                          <div class="comment-inner-container">
                            <div class="avatar">
                              <img class="avatar-item" @click="goToUserProfile(reply.userInfo.userID)" :src="reply.userInfo.headshot || getDefaultAvatarUrl()" alt="User Avatar" />
                            </div>
                            <div class="right">
                              <div class="author-wrapper">
                                <div class="author"><a class="name">{{ reply.userInfo.username }}</a></div>
                              </div>
                              <div class="content">{{ reply.content }}</div>
                              <div class="info">
                                <div class="time">{{ formatDate(reply.creationTime) }}</div>
                                <div class="interactions">
                                  <div class="reply" @click="replyToComment(reply, comment)">
                                    <el-icon><ChatDotRound /></el-icon>
                                    回复
                                  </div>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>

                      <!-- 展开/收起按钮 -->
                      <div v-if="comment.replies.length > 2" class="expand-button" @click="toggleExpandReplies(comment.commentID)">
                        {{ expandedComments[comment.commentID] ? '收起' : `展开全部 ${comment.replies.length} 条回复` }}
                      </div>
                    </div>
                  </div>
                </div>

                <!-- 评论输入框 -->
                <div class="comment-comp">
                  <div class="comment-wrapper">
                    <div class="input-wrapper">
                      <textarea
                          class="comment-input"
                          v-model="commentText"
                          placeholder="添加评论..."
                          @focus="commentInputFocused = true"
                          @blur="commentInputFocused = false"
                      ></textarea>
                      <div class="input-buttons">
                        <span>{{ commentText.length }}/1000</span>
                      </div>
                    </div>
                    <div class="submit" @click="submitComment">发布</div>
                    
                    <!-- 添加收藏按钮 -->
                    <div 
                      class="favorite-button"
                      :class="{ 'favorite-active': isFavorited }"
                      @click="toggleFavorite"
                    >
                      <el-icon><Star /></el-icon>
                      <span class="count">{{ article.favoriteCount || 0 }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-else class="loading-container" @click.stop>
      <el-skeleton :rows="10" animated />
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, watch, computed, nextTick, onUnmounted } from 'vue';
import { Close, Star, ChatDotRound } from '@element-plus/icons-vue';
import { ElMessage } from 'element-plus';
import { TravelNoteApi } from '@/api/new/travelNoteApi.js';
import { CommentApi } from '@/api/CommentApi.js';
import { UserProfileApi } from '@/api/new/userProfleApi.js';
import { FollowRelationApi } from '@/api/FollowRelationApi.js';
import { FavoriteRecordApi } from '@/api/FavoriteRecordApi.js';
import UserUtil from '@/utils/User/User.js';
import { useRouter } from 'vue-router';

const router = useRouter();

const props = defineProps({
  articleId: {
    type: [Number, String],
    required: true
  }
});
const emit = defineEmits(['close']);

// 文章数据
const article = ref({
  title: '',
  content: '',
  creationTime: '',
  author: {
    id: null,
    name: '',
    avatar: ''
  },
  media: [],
  tags: []
});

// 单独维护关注状态
const isFollowed = ref(false);
const isSelf = ref(false);

// 加载状态
const loading = ref(true);

// 评论相关
const comments = ref([]);
const commentText = ref('');
const commentInputFocused = ref(false);
const expandedComments = ref({});
const replyingTo = ref(null);

// 当前用户ID
const currentUserId = computed(() => UserUtil.getUserId() || '0');

// 收藏状态
const isFavorited = ref(false);
const favoriteId = ref(null);

// 获取默认头像URL
const getDefaultAvatarUrl = () => {
  return 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png';
};

// 计算总评论数
const totalComments = computed(() => {
  let count = comments.value.length;
  comments.value.forEach(comment => {
    if (comment.replies) {
      count += comment.replies.length;
    }
  });
  return count;
});

// 获取顶级评论
const topLevelComments = computed(() => {
  return comments.value.filter(comment => !comment.parentCommentID || comment.parentCommentID === 0);
});

// 跳转到用户个人页面
const goToUserProfile = (userId) => {
  if (!userId) return;
  router.push({
    path: '/otherUser',
    query: { userId }
  });
};

// 获取文章详情
const fetchArticleDetails = async (id) => {
  try {
    loading.value = true;
    
    // 获取文章详情
    const articleData = await TravelNoteApi.browseTravelNote(id);
    
    // 获取文章图片
    const imagesData = await TravelNoteApi.getArticleImages(id);
    
    // 获取作者信息
    const authorInfo = await UserProfileApi.getUserInfo(articleData.authorID);
    
    // 检查是否是自己的文章
    isSelf.value = currentUserId.value === articleData.authorID.toString();
    
    // 检查当前用户是否关注了作者
    if (UserUtil.isLogin() && !isSelf.value) {
      try {
        // 使用 FollowRelationApi 获取关注状态
        const followRelation = await FollowRelationApi.getFollowRelationByUserIds(
          currentUserId.value, 
          articleData.authorID
        );
        
        // 如果返回了关注关系对象（不是null），说明已关注
        isFollowed.value = followRelation !== null;
      } catch (error) {
        console.error('获取关注状态失败:', error);
        isFollowed.value = false;
      }
    } else {
      isFollowed.value = false;
    }
    
    // 解析标签
    let parsedTags = [];
    if (articleData.tag) {
      try {
        // 尝试解析 JSON 格式的 tag 字段
        const tagData = JSON.parse(articleData.tag);
        if (tagData && tagData.items && Array.isArray(tagData.items)) {
          // 提取标签名称
          parsedTags = tagData.items.map(item => item.tag);
        }
      } catch (error) {
        console.error('解析标签失败:', error);
        // 如果解析失败，尝试按逗号分隔
        if (typeof articleData.tag === 'string') {
          parsedTags = articleData.tag.split(',').filter(tag => tag.trim());
        }
      }
    }
    
    // 处理文章数据
    article.value = {
      ...articleData,
      media: imagesData.map(img => img.imageUrl) || [],
      author: {
        id: articleData.authorID,
        name: authorInfo.username || '未知用户',
        avatar: authorInfo.headshot || getDefaultAvatarUrl()
      },
      tags: parsedTags
    };
    
    // 检查收藏状态
    if (UserUtil.isLogin()) {
      await checkFavoriteStatus();
    }
    
    // 获取评论
    await fetchComments(id);
    
  } catch (error) {
    console.error('获取文章详情失败:', error);
    ElMessage.error(`获取文章详情失败: ${error.message || '未知错误'}`);
  } finally {
    loading.value = false;
  }
};

// 检查收藏状态
const checkFavoriteStatus = async () => {
  // 检查用户是否登录
  if (!UserUtil.isLogin()) {
    isFavorited.value = false;
    favoriteId.value = null;
    return;
  }
  
  // 获取当前用户ID
  const userId = UserUtil.getUserId();
  if (!userId) {
    isFavorited.value = false;
    favoriteId.value = null;
    return;
  }
  
  try {
    // 调用API检查收藏状态
    const Json_result = await TravelNoteApi.getFavoriteId(userId, props.articleId);
    const result = JSON.parse(Json_result);
    // 设置收藏状态和ID
    isFavorited.value = result.status === "success";
    favoriteId.value = result.status === "success" ? result.favoriteID : null;
  } catch (error) {
    isFavorited.value = false;
    favoriteId.value = null;
  }
};

// 获取评论
const fetchComments = async (articleId) => {
  try {
    // 调用真实的评论API
    const commentsData = await CommentApi.getCommentsByArticleId(articleId);
    
    // 收集所有用户ID
    const userIds = new Set();
    commentsData.forEach(comment => {
      userIds.add(comment.userID);
    });
    
    // 批量获取用户信息
    const userInfoMap = {};
    await Promise.all(Array.from(userIds).map(async (userId) => {
      try {
        const userInfo = await UserProfileApi.getUserInfo(userId);
        userInfoMap[userId] = userInfo;
      } catch (error) {
        console.error(`获取用户 ${userId} 信息失败:`, error);
        // 使用默认用户信息
        userInfoMap[userId] = {
          username: '未知用户',
          headshot: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png'
        };
      }
    }));
    
    // 处理评论数据，将回复组织成扁平结构
    // 一级评论：parentCommentID为0的评论
    const parentComments = commentsData.filter(c => !c.parentCommentID || c.parentCommentID === 0);
    // 二级评论：parentCommentID不为0的评论
    const childComments = commentsData.filter(c => c.parentCommentID && c.parentCommentID !== 0);
    
    // 为每个评论添加用户信息
    const processedComments = parentComments.map(comment => {
      return {
        ...comment,
        userInfo: userInfoMap[comment.userID] || {
          username: '未知用户',
          headshot: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png'
        },
        replies: childComments
          .filter(child => child.parentCommentID === comment.commentID)
          .map(reply => ({
            ...reply,
            userInfo: userInfoMap[reply.userID] || {
              username: '未知用户',
              headshot: 'https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png'
            }
          }))
      };
    });
    
    comments.value = processedComments;
    
  } catch (error) {
    console.error('获取评论失败:', error);
    ElMessage.error(`获取评论失败: ${error.message || '未知错误'}`);
    // 添加备用空数组，确保不会因为评论加载失败而阻止整个页面显示
    comments.value = [];
  }
};

// 提交评论
const submitComment = async () => {
  if (!UserUtil.isLogin()) {
    ElMessage.warning('请先登录后再评论');
    return;
  }
  
  if (!commentText.value.trim()) {
    ElMessage.warning('评论内容不能为空');
    return;
  }
  
  try {
    const userId = currentUserId.value;
    const parentId = replyingTo.value ? replyingTo.value.commentID : 0;
    
    // 创建评论
    const newComment = {
      articleID: props.articleId,
      userID: userId,
      parentCommentID: parentId,
      content: commentText.value,
      creationTime: new Date().toISOString()
    };
    
    // 调用API创建评论
    const result = await CommentApi.createComment(newComment);
    
    // 获取当前用户信息
    const currentUserInfo = await UserProfileApi.getUserInfo(userId);
    
    // 添加用户信息到新评论
    const commentWithUserInfo = {
      ...result, // 使用API返回的评论数据，确保包含commentID
      userInfo: {
        username: currentUserInfo.username,
        headshot: currentUserInfo.headshot || getDefaultAvatarUrl()
      },
      content: commentText.value // 确保使用输入的评论内容
    };
    
    // 更新评论列表
    if (parentId === 0) {
      // 添加为顶级评论
      comments.value.unshift({
        ...commentWithUserInfo,
        replies: []
      });
    } else {
      // 添加为回复
      const parentComment = comments.value.find(c => c.commentID === parentId);
      if (parentComment) {
        if (!parentComment.replies) {
          parentComment.replies = [];
        }
        parentComment.replies.unshift(commentWithUserInfo);
      }
    }
    
    // 清空输入框和回复状态
    commentText.value = '';
    replyingTo.value = null;
    
    ElMessage.success('评论发布成功');
  } catch (error) {
    console.error('发布评论失败:', error);
    ElMessage.error(`发布评论失败: ${error.message || '未知错误'}`);
  }
};

// 回复评论
const replyToComment = (comment, parentComment = null) => {
  if (!UserUtil.isLogin()) {
    ElMessage.warning('请先登录后再回复');
    return;
  }
  
  replyingTo.value = {
    commentID: comment.commentID,
    parentCommentID: parentComment ? parentComment.commentID : comment.commentID
  };
  
  // 直接使用已缓存的用户名
  const username = comment.userInfo ? comment.userInfo.username : '未知用户';
  commentText.value = `回复 @${username}: `;
  
  // 聚焦评论框
  document.querySelector('.comment-input').focus();
};

// 格式化时间
const formatDate = (isoTime) => {
  if (!isoTime) return '';
  
  const date = new Date(isoTime);
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(
    date.getDate()
  ).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(
    2,
    '0'
  )}`;
};

// 切换展开/收起状态
const toggleExpandReplies = (commentID) => {
  expandedComments.value[commentID] = !expandedComments.value[commentID];
};

// 关注/取消关注作者
const toggleFollow = async () => {
  if (!UserUtil.isLogin()) {
    ElMessage.warning('请先登录后再关注');
    return;
  }
  
  const authorID = article.value.author.id;
  const userID = currentUserId.value;
  
  // 不能关注自己
  if (isSelf.value) {
    ElMessage.warning('不能关注自己');
    return;
  }
  
  try {
    if (isFollowed.value) {
      // 取消关注
      await FollowRelationApi.deleteFollowRelation(userID, authorID);
      isFollowed.value = false;
    } else {
      // 关注
      const now = new Date().toISOString();
      await FollowRelationApi.createFollowRelation({
        followerID: userID,
        followedID: authorID,
        createTime: now
      });
      isFollowed.value = true;
    }
    
    ElMessage.success(isFollowed.value ? '已关注作者' : '已取消关注');
  } catch (error) {
    console.error('关注操作失败:', error);
    ElMessage.error(`操作失败: ${error.message || '未知错误'}`);
  }
};

// 切换收藏状态
const toggleFavorite = async () => {
  if (!UserUtil.isLogin()) {
    ElMessage.warning('请先登录');
    return;
  }
  
  try {
    const currentUserId = UserUtil.getUserId();
    const res = await TravelNoteApi.getFavoriteId(currentUserId, props.articleId);
    const response = JSON.parse(res);
    if (response && response.status === 'success') {
      console.log('成功获得收藏', response);
      favoriteId.value = response.favoriteID;
    } else {
      console.log('未能获得收藏', response);
      favoriteId.value = null;
    }

    if (isFavorited.value) {
      // 取消收藏
      console.log('触发取消收藏', favoriteId.value)
      if (favoriteId.value) {
        const deleteResult = await TravelNoteApi.deleteCollection(favoriteId.value);
        isFavorited.value = false;
        favoriteId.value = null;
        
        // 更新收藏数
        if (article.value.favoriteCount > 0) {
          article.value.favoriteCount--;
        }
        
        ElMessage.success('已取消收藏');
      }
    } else {
      // 添加收藏
      const response = await TravelNoteApi.collectTravelNote(props.articleId);
      
      isFavorited.value = true;

      
      // 更新收藏数
      article.value.favoriteCount = (article.value.favoriteCount || 0) + 1;
      
      ElMessage.success('收藏成功');
    }
  } catch (error) {
    console.error('收藏操作失败:', error);
    ElMessage.error('操作失败，请稍后重试');
  }
};

// 关闭模态框的方法
const closeModal = (event) => {
  // 确保点击的是遮罩层本身，而不是其子元素
  if (event.target.classList.contains('note-detail-mask')) {
    // 触发关闭事件
    emit('close');
  }
};

// 监听文章ID变化并获取文章详情
watch(() => props.articleId, (newId) => {
  if (newId) {
    fetchArticleDetails(newId);
  }
}, { immediate: true });

// 生命周期钩子
onMounted(() => {
  if (props.articleId) {
    fetchArticleDetails(props.articleId);
  }
});
</script>

<style scoped lang="less">
.note-detail-mask {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 20;
  display: flex;
  justify-content: center;
  align-items: center;
  
  .loading-container {
    width: 95%;
    max-width: 1400px;
    background-color: white;
    border-radius: 8px;
    padding: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .close-cricle {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 100;
    cursor: pointer;

    .close-mask-white {
      box-shadow:
        0 2px 8px 0 rgba(0, 0, 0, 0.04),
        0 1px 2px 0 rgba(0, 0, 0, 0.02);
      border: 1px solid rgba(0, 0, 0, 0.08);
      background-color: white;
    }

    .close {
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 100%;
      width: 40px;
      height: 40px;
      cursor: pointer;
      transition: all 0.3s;
    }
  }

  .note-container {
    display: flex;
    width: 95%;
    max-width: 1400px;
    height: 95vh;
    background-color: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    
    .media-container {
      flex: 2;
      height: 100%;
      background-color: #f5f5f5;
      display: flex;
      align-items: center;
      justify-content: center;
      
      .no-media {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
      
      .el-carousel {
        width: 100%;
        height: 100%;
        
        :deep(.el-carousel__container) {
          height: 100%;
        }
        
        :deep(.el-carousel__item) {
          display: flex;
          align-items: center;
          justify-content: center;
          
          img {
            width: 100%;
            height: 100%;
            object-fit: contain !important;
          }
        }
      }
    }
    
    .interaction-container {
      width: 450px;
      height: 100%;
      display: flex;
      flex-direction: column;
      border-left: 1px solid #eee;
      position: relative;
      padding-bottom: 80px;
      
      .author-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding: 20px 20px 0;
        
        .author-me {
          display: flex;
          justify-content: space-between;
          align-items: center;
          margin-bottom: 20px;
          
          .info {
            display: flex;
            align-items: center;
            
            .avatar-item {
              border-radius: 50%;
              margin-right: 10px;
              object-fit: cover;
            }
            
            .name {
              font-weight: bold;
              font-size: 16px;
            }
          }
        }
        
        .note-scroller {
          flex: 1;
          overflow-y: auto;
          
          .note-content {
            margin-bottom: 20px;
            
            .title {
              font-size: 24px;
              font-weight: bold;
              margin-bottom: 16px;
            }
            
            .desc {
              font-size: 16px;
              line-height: 1.6;
              margin-bottom: 16px;
              
              .tag {
                display: inline-block;
                padding: 4px 8px;
                background-color: #f5f5f5;
                border-radius: 4px;
                margin-right: 8px;
                margin-bottom: 8px;
                font-size: 12px;
                color: #666;
              }
            }
            
            .bottom-container {
              color: #999;
              font-size: 14px;
            }
          }
          
          .divider {
            height: 1px;
            background-color: #eee;
            margin: 20px 0;
          }
          
          .comments-el {
            .comments-container {
              .total {
                font-weight: bold;
                margin-bottom: 20px;
              }
              
              .list-container {
                .parent-comment {
                  margin-bottom: 20px;
                  
                  .comment-item {
                    margin-bottom: 10px;
                  }
                  
                  .replies-container {
                    margin-left: 40px;
                    
                    .replies-wrapper {
                      max-height: 200px;
                      overflow: hidden;
                      
                      &.expanded {
                        max-height: none;
                      }
                      
                      .reply-item {
                        margin-bottom: 10px;
                      }
                    }
                    
                    .expand-button {
                      color: #1890ff;
                      cursor: pointer;
                      margin-top: 10px;
                      font-size: 14px;
                    }
                  }
                }
                
                .comment-inner-container {
                  display: flex;
                  
                  .avatar {
                    margin-right: 12px;
                    
                    .avatar-item {
                      width: 32px;
                      height: 32px;
                      border-radius: 50%;
                      object-fit: cover;
                    }
                  }
                  
                  .right {
                    flex: 1;
                    
                    .author-wrapper {
                      margin-bottom: 4px;
                      
                      .author {
                        font-weight: bold;
                      }
                    }
                    
                    .content {
                      margin-bottom: 8px;
                      line-height: 1.5;
                    }
                    
                    .info {
                      display: flex;
                      justify-content: space-between;
                      color: #999;
                      font-size: 12px;
                      
                      .interactions {
                        display: flex;
                        
                        .reply {
                          margin-left: 16px;
                          cursor: pointer;
                          
                          &:hover {
                            color: #1890ff;
                          }
                        }
                      }
                    }
                  }
                }
              }
              
              .comment-comp {
                position: absolute;
                bottom: 0;
                left: 0;
                width: 100%;
                padding: 15px 20px;
                background-color: white;
                border-top: 1px solid #eee;
                box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
                box-sizing: border-box;
                
                .comment-wrapper {
                  display: flex;
                  align-items: center;
                  
                  .input-wrapper {
                    flex: 1;
                    position: relative;
                    
                    .comment-input {
                      width: 100%;
                      padding: 10px 40px 10px 15px;
                      border: 1px solid #ddd;
                      border-radius: 20px;
                      resize: none;
                      height: 40px;
                      line-height: 20px;
                      
                      &:focus {
                        outline: none;
                        border-color: #1890ff;
                      }
                    }
                    
                    .input-buttons {
                      position: absolute;
                      right: 15px;
                      top: 50%;
                      transform: translateY(-50%);
                      color: #999;
                      font-size: 12px;
                    }
                  }
                  
                  .submit {
                    margin-left: 10px;
                    background-color: #1890ff;
                    color: white;
                    padding: 0 20px;
                    height: 40px;
                    line-height: 40px;
                    border-radius: 20px;
                    cursor: pointer;
                    
                    &:hover {
                      background-color: #40a9ff;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .note-detail-mask {
    .note-container {
      flex-direction: column;
      width: 95%;
      height: 95vh;
      
      .media-container {
        height: 40vh;
      }
      
      .interaction-container {
        width: 100%;
        height: auto;
        max-height: 55vh;
      }
    }
  }
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.favorite-button {
  //display: flex;
  //align-items: center;
  //gap: 5px;
  background-color: #f2f2f2;
  color: #666;

  margin-left: 10px;
  //background-color: #1890ff;
  //color: white;
  padding: 0 20px;
  height: 40px;
  line-height: 40px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;

  &.favorite-active {
    background-color: #ff2442;
    color: #fff;
  }
  
  .count {
    margin-left: 2px;
  }
}
</style>